<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\Store;
use App\User;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\InfoBox;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return Admin::content(function (Content $content) {
            $content->header('统计数据');

            $content->description('现在时间：'.date('Y-m-d H:i:s', time()));
            $content->row(function ($row) {
                $row->column(4, new InfoBox('销售总额', 'book', 'aqua', '/admin/orders', Order::saleMoneyCount()));
                $row->column(2, new InfoBox('会员总数', 'book', 'yellow', '/admin/users', User::total()));
                $row->column(2, new InfoBox('代理总数', 'book', 'green', '/admin/users',User::getPorxyCount()));
                $row->column(2, new InfoBox('订单总数', 'book', 'aqua', '/admin/orders', Order::count()));
                //$row->column(2, new InfoBox('筛查订单总数', 'book', 'green', '#',5));
               // $row->column(2, new InfoBox('产品订单总数', 'book', 'yellow', '#', 6));
                $row->column(2, new InfoBox('未支付订单数', 'book', 'green', '/admin/orders?order_status=0', Order::getCountByStatus(0)));
                $row->column(2, new InfoBox('待发货订单数', 'book', 'yellow', '/admin/orders?order_status=1',Order::getCountByStatus(1)));
                $row->column(2, new InfoBox('已发货订单数', 'book', 'aqua', '/admin/orders?order_status=2', Order::where([
                    ['is_pay', '=', '1'],
                    ['is_send', '=', '1'],
                ])->count()));
                $row->column(2, new InfoBox('已收货订单数', 'book', 'green', '/admin/orders?order_status=3', Order::where([
                    ['is_pay', '=', '1'],
                    ['is_send', '=', '1'],
                    ['is_receive', '=', '1'],
                ])->count()));
            });
            //$store = Store::whereNull('deleted_at')->orderBy('id','desc')->get();
            $data = [];
           /* if($store->first()){
                foreach($store as $k=>$v){
                    $id = $v->id;
                    $name = $v->name;
                    $data[$k]['id'] =   $id;
                    $data[$k]['name'] =   $name;
                    $data[$k]['users'] = 1;
                    $data[$k]['orders'] = 2;
                    $data[$k]['sales'] = 3;
                    $data[$k]['order'] = 4;
                    $data[$k]['order1'] = 5;
                    $data[$k]['order2'] = 5;
                    $data[$k]['order3'] = 7;
                }
            }*/
           // $content->body(new Box('门店数据', view('admin.sparkline.bar',compact('data'))));
           // $content->body(new Box('门店数据', view('admin.sparkline.bar',compact('data'))));
        });
    }
}
